﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.7/iconfont.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>新建网站权限组</title>
</head>
<body>
<div class="pd-20">
	<form action="" method="post" class="form form-horizontal" id="form1">
		<div class="row cl">
			<label class="form-label col-2"><span class="c-red">*</span>权限组名称：</label>
			<div class="formControls col-6">
				<input type="text" class="input-text" value="" placeholder="" id="title" name="title" nullmsg="权限组名称不能为空！" datatype="s1-16">
			</div>
			<div class="col-1"></div>
		</div>
		<!-- <div class="row cl">
			<label class="form-label col-2">备注：</label>
			<div class="formControls col-10">
				<input type="text" class="input-text" value="" placeholder="" id="" name="">
			</div>
		</div> -->
		<div class="row cl">
		    <label class="form-label col-2"><!-- <span class="c-red">*</span> -->状态：</label>
		    <div class="formControls col-8 s-msg" style="padding-top: 2px;">
		        <div class="radio-box">
		            <input type="radio" id="radio-1" name="status" value="1">
		            <label for="radio-1" class="lh-26">显示</label>
		        </div>
		        <div class="radio-box">
		            <input type="radio" id="radio-2" name="status" value="0">
		            <label for="radio-2" class="lh-26">不显示</label>
		          </div>
		    </div>
		</div>
		<div class="row cl">
			<label class="form-label col-2">权限组权限：</label>
			<div class="formControls col-10" id="content_sp">
			</div>
		</div>
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</div>

<script id="test" type="text/html">
<% for (x in list) { %>
	<dl class="permission-list">
		<dt>
			<label>
				<input type="checkbox" value="" name="user-Character-0" id="user-Character-0">
				<%=list[x].title%>
			</label>
		</dt>

		<dd>
			<dl class="cl permission-list2">
				<dd style="margin-left: 0px;">
				<%for (j in list[x].child){%>
					<label class="" style="display: inline-block;">
						<input type="checkbox" value="<%=list[x].child[j].id%>" name="rules[]" id="user-Character-0-1-0" 
						
						<% if(typeof(ss)!= "undefined" ){
						var brandlist=ss.split(',');
						for (t in brandlist){
						if(brandlist[t]==list[x].child[j].id){%>
							checked='checked'
						<%
							}}}
						%>

						>
						
						<span class="s-pointer" title="<%=list[x].child[j].name%>"><%=list[x].child[j].title%></span>
					</label>
				<%}%>
				</dd>
			</dl>
		</dd>

	</dl>
<%}%>
</script>	
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 

<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script>
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script>
<script type="text/javascript" src="js/s.js"></script> 
<script type="text/javascript" src="js/template-native.js"></script> 
<script>
$(function(){
	
var ss='abcd';


	var editid=getUrlParam('editid');//编辑权限id

	if(editid==null){
	    $("#form1").attr("action", API_AUTH_GROUP);
    	// 罗列权限列表
    	$.getJSON(API_AUTH,function(data2){
    		var data={'list':data2.datas};
    		var html=template('test',data);
    		document.getElementById('content_sp').innerHTML=html;
    		// 全选按钮
    		$(".permission-list dt input:checkbox").click(function(){
    			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
    		});
    	})
	}else{

	    var editurl=API_AUTH_GROUP+"?id="+editid;
	    $("#form1").attr("action", editurl);
	    // 读取权限组信息
	    $.getJSON(editurl,function(data){
	    	if(!checkStatus(data)) return;

            var rules=data.datas.rules;
            $("#title").val(data.datas.title);
            if(data.datas.status=='0'){
                $("#radio-2").attr("checked","checked");
            }else{
                $("#radio-1").attr("checked","checked");
            } 

        	// 罗列权限列表
        	$.getJSON(API_AUTH,function(data2){
        		var data={'list':data2.datas,'ss':rules};
        		var html=template('test',data);
        		document.getElementById('content_sp').innerHTML=html;
        		// 全选按钮
        		$(".permission-list dt input:checkbox").click(function(){
        			$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
        		});
        	})

	    
	        
	    })
	}

	

	// $("#form1").Validform({
	// 	tiptype:2,
 //        ajaxPost:true,
	// 	callback:function(data){
	// 		if(!checkStatus(data)) return;
	//         if(data.status=='1'){
 //               var index = parent.layer.getFrameIndex(window.name);
 //               parent.parent.layer.msg("操作成功", {icon:1,time:1000});
 //               parent.$('.btn-refresh').click();
 //               window.parent.location.reload();
 //               parent.layer.close(index);      
 //           }
	// 	}
	// });
	Validformsubmit("#form1");


});
</script>
</body>
</html>